package com.dsr.controller;

import com.dsr.consts.Result;
import com.dsr.entity.Section;
import com.dsr.service.SectionService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * (Section)表控制层
 *
 * @author dsr
 * @since 2020-08-16
 */
@Api(tags = "(Section)表控制层")
@RestController
@RequestMapping("/section")
public class SectionController {

    @Autowired
    private SectionService sectionService;

    @ApiOperation("更具id获取实体")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "id", required = true)
    })
    @GetMapping("/get/{id}")
    public Result getEntity(@PathVariable String id) {
        return sectionService.getEntity(id);
    }

    @ApiOperation("保存操作")
    @ApiParam(name = "section", value = "实体", required = true)
    @PostMapping("/save")
    public Result save(@RequestBody Section section) {
        return sectionService.save(section);
    }

    @ApiOperation("更新操作")
    @ApiParam(name = "section", value = "实体", required = true)
    @PutMapping("/update")
    public Result update(@RequestBody Section section) {
        return sectionService.update(section);
    }

    @ApiOperation("根据id删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id(ps:1,2,3)", required = true)
    })
    @DeleteMapping("/delete")
    public Result delete(@RequestBody String id) {
        return sectionService.delete(id);
    }

    @ApiOperation("查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "页", required = true),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页大小", required = true),
    })
    @ApiParam(name = "section", value = "查询字段", required = true)
    @PostMapping("/list/{page}/{size}")
    public Result query(@PathVariable int page, @PathVariable int size, @RequestBody Section section) {
        return sectionService.query(page, size, section);
    }

    @ApiOperation("返回所有")
    @GetMapping("/list")
    public Result list() {
        return sectionService.list();
    }

    @ApiOperation("查询子节点所有")
    @GetMapping("/listChildren")
    public Result listChildren() {
        return sectionService.listChildren();
    }
}